#ifndef __DES3_H__
#define __DES3_H__

/**
	Triple_DES encrypt and decrypt
*/
#ifdef __cplusplus
extern "C" {
#endif

    typedef unsigned char   bits8_t;    /* 8  bits */
    typedef unsigned short  bits16_t;   /* 16 bits */
    typedef unsigned long   bits32_t;   /* 32 bits */

    typedef signed char     sbits8_t;   /* 8  bits */
    typedef signed short    sbits16_t;  /* 16 bits */
    typedef signed long     sbits32_t;  /* 32 bits */

    typedef bits32_t DES_KS[16][2];	    /* Single-key DES key schedule */
    typedef bits32_t DES3_KS[48][2];	/* Triple-DES key schedule */


    typedef struct
    {
        int				decrypt;
        DES3_KS			keysched;
        unsigned char	iv [8];
    }  DES3_CTX;

#define DES3_IN_LEN(x)     ((x) & ~7)
#define DES3_OUT_LEN(x)    (((x) + 8) & ~7)  /* always try to add 8 bytes */


    void     des3cbc_init_context (void *ctx, bits8_t *key, int decrypt);
    void     des3cbc_iv_context (void *ctx, bits8_t *iv);
    void     des3cbc_crypt (void *ctx, bits8_t *in, bits8_t *out, bits32_t n);
    bits32_t des3cbc_crypt_pkcs7(void *ctx, bits8_t *in, bits32_t in_len, bits8_t *out, bits32_t out_len);

    void     des3ecb_init_context (void *ctx, bits8_t *key, int decrypt);
    void     des3ecb_crypt (void *ctx, bits8_t *in, bits8_t *out, bits32_t n);
    bits32_t des3ecb_crypt_pkcs7(void *ctx, bits8_t *in, bits32_t in_len, bits8_t *out, bits32_t out_len);

#ifdef __cplusplus
}
#endif
#endif /* __DES3_H__ */
